using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.ComponentModel.Design;
using EnvDTE;
using System.ComponentModel.Design.Serialization;

namespace XnaDesignerGenerator
{
    [ToolboxItemFilter("XnaComponent", ToolboxItemFilterType.Require)]
    [DesignerSerializer(typeof(XnaGameGenerator),typeof(CodeDomSerializer))]
    public class XnaGame : Component,XnaComponent
    {
        public XnaGame()
        {
            InitializeComponent();
        }

        private Type gameType;
        
        [Category("Xna")]
        [TypeConverter(typeof(GameTypeListConverter))]
        public Type GameType
        {
            get { return gameType; }
            set
            {
                gameType = value;
            }
        }

        private Project project;

        [DesignOnly(true)]
        [Category("Xna")]
        [TypeConverter(typeof(ProjectTypeConverter))]
        public Project Project
        {
            get { return project; }
            set { project = value; }
        }

        private Microsoft.Xna.Framework.Game game;

        [TypeConverter(typeof(ExpandableObjectConverter))]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Microsoft.Xna.Framework.Game Game
        {
            get { return game; }
            set
            {
                game = value;
                if (gameType == null)
                    gameType = game.GetType();
                if (project == null)
                {
                    Project projectExistent = (Project)TypeDescriptor.GetConverter(typeof(Project)).ConvertFrom(gameType.Namespace);
                    if (projectExistent != null)
                    {
                        project = projectExistent;
                    }
                }

            }
        }


        private void InitializeComponent()
        {

        }
    }
}
